
function queryCategory2ByCategory1(){
	var params={
		category1Id:$('#category1Select').attr('value')
	};
	
	$.ajax({
		type:"POST",
		url:"categoryAjax_queryCategory2ByCategory1.action",
		dataType:"json",
		data:params,
		success:function(msg){
			$('#category2Select').get(0).options.length=0;
			$('#category3Select').get(0).options.length=0;
			
			$('#category2Select').get(0).options.add(new Option('=请选择=',0));
			$('#category3Select').get(0).options.add(new Option('=请选择=',0));
			
			var data = eval("("+msg+")"); 
			$.each(data,function(index,data){
				var category2Id = data.id;
				var category2Name = data.categoryName;
				$('#category2Select').get(0).options.add(new Option(category2Name,category2Id));
				
			})
		},
		error:function(er){
			//alert(er.responseText);
			alert('系统出错')
		}
	})
}

function changePriceValueSelected(){
	$('#descriptionSelected').val($('#productDetailPriceValueSelect').getSelectedText());
}

function queryCategory3ByCategory2(){
	//alert($('#productDetailPriceValueSelect').getSelectedText());
	//$('#descriptionSelected').val($('#productDetailPriceValueSelect').getSelectedText());
	//alert($('#descriptionSelected').val())
	var params={
		category2Id:$('#category2Select').attr('value')
	};

	$.ajax({
		type:"POST",
		url:"categoryAjax_queryCategory3ByCategory2.action",
		dataType:"json",
		data:params,
		success:function(msg){
			$('#category3Select').get(0).options.length=0;
			$('#category3Select').get(0).options.add(new Option('=请选择=',0));
			
			var data = eval("("+msg+")"); 
			$.each(data,function(index,data){
				var category3Id = data.id;
				var category3Name = data.categoryName;
				$('#category3Select').get(0).options.add(new Option(category3Name,category3Id));
			})
		},
		error:function(er){
			//alert(er.responseText);
			alert('系统出错')
		}
	})
}


//productAdd1_1.jsp 


function queryPriceValueList(){
	var priceTitleId = $('#productDetailPriceTitleSelect').val();
	$('#titleSelected').val($('#productDetailPriceTitleSelect').getSelectedText());
	if(priceTitleId==null || priceTitleId=='' || priceTitleId=='0'){
		//alert('请选择名称框中有效数据项');
		return ; 
	}
	
	var params={
		priceTitleId:priceTitleId
	};

	$.ajax({
		type:"POST",
		url:"productAjax_queryPriceValueList.action",
		dataType:"json",
		data:params,
		success:function(msg){
			$('#productDetailPriceValueSelect').get(0).options.length=0;
			//$('#productDetailPriceValueSelect').get(0).options.add(new Option('=请选择=',0));
			var data = eval("("+msg+")"); 
			$.each(data,function(index,data){
				var key = data.id;
				var value = data.description;
				$('#productDetailPriceValueSelect').get(0).options.add(new Option(value,key));
			})
		},
		error:function(er){
			//alert(er.responseText);
			alert('系统出错')
		}
	})
}


function addProductDetailPriceTitle(){
	var isRealPrice = $('input[name="isRealPrice"]').filter(':checked').val();
	var title = $('#title').val();
	var productId = $("#productId").val();
	if(productId==''){
		alert('未加载商品');
		return ;
	}
	
	var params={
		isRealPrice:isRealPrice,
		title:title,
		productId:productId
	};

	$.ajax({
		type:"POST",
		url:"productAjax_addProductDetailPriceTitle.action",
		dataType:"json",
		data:params,
		success:function(msg){
			var data = eval("("+msg+")"); 
			var responseCode = data.responseCode;
			var responseContent = data.responseContent;
			var title = data.title;
			var id = data.id;
			if(responseCode==0){
				alert(responseContent);
				return ;
			}
			$('#productDetailPriceTitleSelect').get(0).options.add(new Option(title,id));
		},
		error:function(er){
			//alert(er.responseText);
			alert('系统出错')
		}
	})
	
}

function addProductDetailPriceValue(){
	var description = $('#description').val();
	var priceYuan = $("#priceYuan").val();
	var amountStore = $("#amountStore").val();
	var priceTitleId = $('#productDetailPriceTitleSelect').val();
	if(priceTitleId==null || priceTitleId=='' || priceTitleId=='0'){
		alert('请选择名称框中有效数据项');
		return ; 
	}
	
	var params={
		priceTitleId:priceTitleId,
		priceYuan:priceYuan,
		description:description,
		amountStore:amountStore
	};

	$.ajax({
		type:"POST",
		url:"productAjax!addProductDetailPriceValue.action",
		dataType:"json",
		data:params,
		success:function(msg){
			var data = eval("("+msg+")"); 
			var responseCode = data.responseCode;
			var responseContent = data.responseContent;
			var description = data.description;
			var id = data.id;
			if(responseCode==0){
				alert(responseContent);
				return ;
			}
			$('#productDetailPriceValueSelect').get(0).options.add(new Option(description,id));
		},
		error:function(er){
			//alert(er.responseText);
			alert('系统出错')
		}
	})
	
}

function modifyProductDetailPriceTitle(){
	var priceTitleId = $('#productDetailPriceTitleSelect').val();
	var title = $('#titleSelected').val();
	var productId = $("#productId").val();
	
	if(productId==''){
		alert('未加载商品');
		return ;
	}
	
	var params={
		priceTitleId:priceTitleId,
		title:title,
		productId:productId
	};

	$.ajax({
		type:"POST",
		url:"productAjax!modifyProductDetailPriceTitle.action",
		dataType:"json",
		data:params,
		success:function(msg){
			var data = eval("("+msg+")"); 
			var responseCode = data.responseCode;
			var responseContent = data.responseContent;
			var titleShow = data.titleShow;
			var id = data.id;
			if(responseCode==0){
				alert(responseContent);
				return ;
			}
			$($("#productDetailPriceTitleSelect option")[$("#productDetailPriceTitleSelect").getSelectedIndex()]).text($("#titleSelected").val());
		},
		error:function(er){
			//alert(er.responseText);
			alert('系统出错')
		}
	})
}

function modifyProductDetailPriceValue(){

	var description = $('#descriptionSelected').val();
	var priceValueId = $('#productDetailPriceValueSelect').val();
	var priceTitleId = $('#productDetailPriceTitleSelect').val();
	if(priceTitleId==null || priceTitleId=='' || priceTitleId=='0'){
		alert('请选择分类框中有效数据项');
		return ; 
	}
	if(priceValueId ==null || priceValueId=='' || priceValueId=='0'){
		alert('请选择分类详细框中有效数据项');
		return ; 
	}
	
	var params={
		priceTitleId:priceTitleId,
		priceValueId:priceValueId,
		description:description
	};

	$.ajax({
		type:"POST",
		url:"productAjax!modifyProductDetailPriceValue.action",
		dataType:"json",
		data:params,
		success:function(msg){
			var data = eval("("+msg+")"); 
			var responseCode = data.responseCode;
			var responseContent = data.responseContent;
			var descriptionShow = data.descriptionShow;
			var id = data.id;
			if(responseCode==0){
				alert(responseContent);
				return ;
			}
			$($("#productDetailPriceValueSelect option")[$("#productDetailPriceValueSelect").getSelectedIndex()]).text($("#descriptionSelected").val());
		},
		error:function(er){
			//alert(er.responseText);
			alert('系统出错')
		}
	})
}

function delProductDetailPriceTitle(){
	var priceTitleId = $('#productDetailPriceTitleSelect').val();
	var productId = $("#productId").val();
	
	if(productId==''){
		alert('未加载商品');
		return ;
	}
	
	var params={
		priceTitleId:priceTitleId,
		productId:productId
	};

	$.ajax({
		type:"POST",
		url:"productAjax!delProductDetailPriceTitle.action",
		dataType:"json",
		data:params,
		success:function(msg){
			var data = eval("("+msg+")"); 
			var responseCode = data.responseCode;
			var responseContent = data.responseContent;
			var titleShow = data.titleShow;
			var id = data.id;
			if(responseCode==0){
				alert(responseContent);
				return ;
			}
			$('#productDetailPriceTitleSelect').removeSelected();
		},
		error:function(er){
			//alert(er.responseText);
			alert('系统出错')
		}
	})
}

function delProductDetailPriceValue(){
	var priceValueId = $('#productDetailPriceValueSelect').val();
	var priceTitleId = $('#productDetailPriceTitleSelect').val();
	
	if(priceTitleId==null || priceTitleId=='' || priceTitleId=='0'){
		alert('请选择分类框中有效数据项');
		return ; 
	}
	if(priceValueId ==null || priceValueId=='' || priceValueId=='0'){
		alert('请选择分类详细框中有效数据项');
		return ; 
	}
	
	var params={
			priceTitleId:priceTitleId,
			priceValueId:priceValueId
		};

		$.ajax({
			type:"POST",
			url:"productAjax!delProductDetailPriceValue.action",
			dataType:"json",
			data:params,
			success:function(msg){
				var data = eval("("+msg+")"); 
				var responseCode = data.responseCode;
				var responseContent = data.responseContent;
				var descriptionShow = data.descriptionShow;
				var id = data.id;
				if(responseCode==0){
					alert(responseContent);
					return ;
				}
				$('#productDetailPriceValueSelect').removeSelected();
			},
			error:function(er){
				//alert(er.responseText);
				alert('系统出错')
			}
		})
}

function queryProductSonById(o){	
	var productSonId = o.id;
	
	$('#productSonListTable').find('tr').each(function(){
		this.bgColor='#FFFFFF';
		if(this.id==productSonId){
			this.bgColor='#FFCCCC';
		}
	})
	
	
	
	if(productSonId ==null || productSonId=='' || productSonId=='0'){
		alert('选择信息不正确，重新刷新页面');
		return ; 
	}
	
	var params={
		productSonId:productSonId
	};

	$.ajax({
		type:"POST",
		url:"productAjax!queryProductSonById.action",
		dataType:"json",
		data:params,
		success:function(msg){
		
			var data = eval("("+msg+")");
			//for
			var strTmp = data.position;
			
			var index = strTmp.indexOf(',');
			//alert(index);
			while(-1 != index)
			{
				$("input[type=radio][value="+strTmp.substring(0,index)+"]").attr("checked",'checked');
				strTmp = strTmp.substring(index+1);
				index = strTmp.indexOf(',');
			};
			
			$('input:text[name="agent"]').val(data.lastProductRecordDto.agent);
			//$('input:text[name="agentDate"]').val(data.lastProductRecordDto.agentDate);
			$('#agentDate').datebox("setValue",data.lastProductRecordDto.agentDate);
			
			$('input:text[name="dealer"]').val(data.lastProductRecordDto.dealer);
			//$('input:text[name="inPriceYuan"]').attr("value",data.inPriceYuan);
			//$('input:text[name="marketPriceYuan"]').val(data.marketPriceYuan);
			//$('input:text[name="productPriceYuan"]').val(data.productPriceYuan);
			$('#inPriceYuan').numberbox("setValue",data.inPriceYuan);
			$('#marketPriceYuan').numberbox("setValue",data.marketPriceYuan);
			$('#productPriceYuan').numberbox("setValue",data.productPriceYuan);
			
			$('input:text[name="amountStore"]').val(data.amountStore);
			$('input:text[name="amountStore"]').attr("text",data.amountStore);
			$('input:text[name="storeAddress"]').val(data.storeAddress);
			
		},
		error:function(er){
			//alert(er.responseText);
			alert('系统出错')
		}
	})
}




